package com.sgb.kjwl.viewmodel.self.goods;

import android.app.Application;
import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.core.util.Pair;
import androidx.lifecycle.MutableLiveData;

import com.jyb.qiyefuwu.view.activity.usercenter.SalesOrderDetailsActivity;
import com.sgb.kjwl.api.NewAPIManager;
import com.sgb.kjwl.model.entity.self.VipPriceMangeListEntity;
import com.sgb.link.api.ApiManager;
import com.sgb.link.router.PathGoods;
import com.sgb.link.router.PathUser;
import com.swgk.core.base.api.APIManager;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.base.model.entity.ListResponse;
import com.swgk.core.common.base.BaseViewModel;
import com.swgk.core.common.utils.ActivityJump;
import com.swgk.core.xrecyclerview.XRecyclerView;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * @author admin
 */
public class ChoiceVipPriceGoodsViewModel extends BaseViewModel implements XRecyclerView.LoadingListener {
    public ChoiceVipPriceGoodsViewModel(@NonNull @NotNull Application application) {
        super(application);
    }

    public MutableLiveData<List<VipPriceMangeListEntity>> listdata = new MutableLiveData<>();
    public MutableLiveData<String> dialog_show_text = new MutableLiveData<>();
    public MutableLiveData<String> ok = new MutableLiveData<>();
    private int page = 1;
    public boolean isloadmore;


    private void getData(boolean isloadmore) {
        this.isloadmore = isloadmore;
        page = isloadmore ? page + 1 : 1;

        HashMap<String, Object> body = new HashMap<>();
        body.put("page", page);
        body.put("limit", 20);
        mLoading.postValue(SHOW_LODING);
        NewAPIManager.getInstance().getMemberPriceAPI().getCanSetGoodsList(body).enqueue(new ICallBack<BaseEntity<ListResponse<List<VipPriceMangeListEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<VipPriceMangeListEntity>>> data) {
                listdata.postValue(data.getData().getList());
            }
        });
    }


    public void getGoosType(long itemId) {
        mLoading.postValue(SHOW_LODING);
        NewAPIManager.getInstance().getMemberPriceAPI().getGoodsSku("item/member/sku/list/" + itemId).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                mLoading.postValue(DISMISS_LODING);
                if (response.body() == null) {
                    return;
                }
                if (APIManager.RESPONSE_OK.equals(response.body().getState())) {
                    ok.postValue(itemId + "");
                } else {
                    dialog_show_text.postValue(response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                mLoading.postValue(DISMISS_LODING);
                mToast.postValue(t.getMessage());
            }
        });
    }

    @Override
    public void onRefresh() {
        getData(false);
    }

    @Override
    public void onLoadMore() {
        getData(true);
    }
}
